package fi.profecons.csswindows.toolkit;

import fi.profecons.csswindows.ActionListener;
import fi.profecons.csswindows.Element;
import fi.profecons.csswindows.Container;

public class ContentPane extends Container implements ActionListener {

	public final static int SCROLLBAR_NONE = 0;

	public final static int SCROLLBAR_AUTO = 1;

	public final static int SCROLLBAR_AUTO_X = 2;

	public final static int SCROLLBAR_AUTO_Y = 3;

	public final static int SCROLLBAR_X = 4;

	public final static int SCROLLBAR_Y = 5;

	public final static int SCROLLBAR_BOTH = 6;
	
	public final static int KEY_LEFT = 37;
	
	public final static int KEY_UP = 38;
	
	public final static int KEY_RIGHT = 39;
	
	public final static int KEY_DOWN = 40;

	public ContentPane() {
		super();
		setActionListener(this);
		addCommand("new ContentPane('" + getId() + "');");
	}

	public void setScrollBarMode(int mode) {
		switch (mode) {
		case SCROLLBAR_NONE:
			addCommand("getElement('" + getId()
					+ "').setScrollBarMode('hidden');");
			break;
		case SCROLLBAR_AUTO:
			addCommand("getElement('" + getId()
					+ "').setScrollBarMode('auto');");
			break;
		case SCROLLBAR_AUTO_X:
			addCommand("getElement('" + getId()
					+ "').setScrollBarMode('auto', 'x');");
			break;
		case SCROLLBAR_AUTO_Y:
			addCommand("getElement('" + getId()
					+ "').setScrollBarMode('auto', 'y');");
			break;
		case SCROLLBAR_X:
			addCommand("getElement('" + getId()
					+ "').setScrollBarMode('scroll', 'x');");
			break;
		case SCROLLBAR_Y:
			addCommand("getElement('" + getId()
					+ "').setScrollBarMode('scroll', 'y');");
			break;
		case SCROLLBAR_BOTH:
			addCommand("getElement('" + getId()
					+ "').setScrollBarMode('scroll');");
			break;
		}
	}

	public void organizeIcons(boolean all) {
		if (all) {
			addCommand("getElement('" + getId() + "').organizeIcons(true);");
		} else {
			addCommand("getElement('" + getId() + "').organizeIcons(false);");
		}
	}

	public void handleAction(Element e, String action) {
		if (action.equals("resize")) {
			this.refresh();
		}

	}

	public void handleAction(Element target, Element source, String action) {
		
	}
}
